Skip to content

test(studio): the preview regression runs green against a sealed preview - #8470

Merged
miguel-heygen merged 4 commits into
mainfrom
fix/sealed-release-seek-race
Nov 22, 2026
Merged

miguel-heygen merged 4 commits into
mainfrom
fix/sealed-release-seek-race

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

preview-video-regression.mjs now runs green against a sealed Studio preview (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1) as well as an unsealed one. Two of its steps assumed a frame Studio can script. Test only; no product code changes.

Why

Both steps fail the same way on main sealed, independent of any product change.

  1. Slider release, then the script's own seek.
    • The script drags the "Seek preview" slider, releases it, then seeks inside the frame with window.__player.seek(7).
    • Unsealed, Studio's release seek is a direct call made before mouseup returns, so the script's seek lands second.
    • Sealed, Studio's release seek is a posted message. Traced in the frame, it arrived 17 ms after the script's in-frame seek and overwrote it ("Seek to 7 did not publish", time 9.667).
    • Every seek Studio itself makes goes through the bridge in order. Only code running in the frame can land in that window.
  2. The held media answer had no CORS grant.
    • The delayed-native step answers a video's first range request with a 16 KB prefix and holds the next.
    • A sealed frame's own media loads with crossorigin="anonymous", and the preview server grants it with Access-Control-Allow-Origin: null plus exposed headers.
    • The fake answer had none, so the browser blocked it ("Access to video … blocked", net::ERR_FAILED). The video errored instead of stalling, and no range request was ever held ("Native delivery was not actually held").

How

  1. After the slider's mouseup, the page posts its own message to the frame and the script waits until the frame receives it, then seeks. Studio posts its release seek synchronously from the same page, messages from one window to the frame arrive in order, and the runtime applies a control seek as it arrives, so by then the release seek has landed. The same code runs in both modes; unsealed there is no posted seek and it returns at once. (A first version waited for the frame clock to show the slider's value. Under load that passed on the last drag step's value before the release's own seek arrived, so it was replaced.)
  2. Before answering, the fake prefix answer asks the preview server for one byte of the same URL, with the request's own Origin and Sec-Fetch-Dest: video, and copies back exactly the CORS headers the server returns (access-control-*, vary, x-content-type-options). The answer can't drift from the server's own grant. An unsealed request sends no Origin and gets none, so it is unchanged.

Test plan

  • fails without the fix: packages/studio/tests/e2e/preview-video-regression.mjs (run against a sealed Studio).
    • Without these two commits, on the devbox: "Seek to 7 did not publish" in one run, and "Native delivery was not actually held" or the frame navigating in the delayed-native step in the other.
    • Main fails the same two steps sealed. Its runs had the paused-canvas assertions cut, because main stops earlier sealed with no decoded paused frame; that is fixed separately in fix(studio): a sealed preview shows paused video frames from Studio's decoder #8466.
  • With these commits on top of fix(studio): a sealed preview shows paused video frames from Studio's decoder #8466 (devbox, Studio dev server, the fixture generated fresh): unsealed passes 2 of 2 and sealed passes 2 of 2 at moderate load.
  • On a quieter machine (a macOS box at load about 5, same trees, 3 runs per mode): all 6 runs pass the drag, the release-then-seek step and the scene cut, with no dev-server websocket drop. All 6 then stop at a later step that main also fails on macOS (decoded covers stay after play); CI runs this on Linux, where main passes it, so that is separate.
  • Under heavy load (devbox at load 25 to 50): some runs lose the page when Vite's dev-server websocket drops and reloads it. Every such failure had a websocket drop, and no run without one failed that way. On main, CI's step for this script passed 15 of 15 in the last 30 runs that reached it, so this is the loaded box, not the script.
  • Under load the drag-0.7 picture sometimes shows a black background at scene B's first frame. Sampling the real pixels through the same drag shows a one-sample (about 50 to 70 ms) black flash right after the drag crosses into scene B, in both modes (unsealed 3 of 3, sealed 2 of 3). It is a real flash at a clip cut while scrubbing, present on main unsealed, not a sealed gap. It is fixed separately; this PR leaves the assertion as it is.
  • tsc, Fallow and pre-push clean.

No visible change

Only the end-to-end script changes; nothing a person sees in Studio.

Related work

Refs #8466 (sealed paused frames), Refs #7846 (the sealed-by-default preview).

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.

Need ✅ · Size ✅ (+38/−3, one e2e script) · Reuse ✅ (the fake media answer copies the preview server's own CORS headers rather than restating them) · Simpler ✅ · Structure ✅
Risk: low. This is test-only code.

Checked at 38ef89c.

  • The barrier is sound. Studio posts its release seek synchronously from the page during mouseup. Messages from one window to the frame arrive in order. So once the frame receives the script's own preview-regression-barrier message, posted after mouseup, the release seek has been delivered, and the in-frame seek(7) lands last. The listener is attached before the message is posted, and it removes itself.
  • The CORS copy can't drift. serverCorsFor is used only when the request carries an Origin, which only the sealed frame's crossorigin media sends. It asks the server for one byte of the same URL with that origin and copies only access-control-*, vary and x-content-type-options. Unsealed requests get {}, so they are unchanged. respondPrefix is now awaited inside its own async function and the request handler calls it with void, so interception order is unchanged.
  • The preview-regression and Preview parity CI steps pass at this head. The body has the fails without the fix: line naming the script, with the two failure messages it showed on main sealed.

— Rames (hf-review)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at a6cdb13. The only change since my approval at 38ef89c is the barrier's message check. It now resolves only for a message whose origin equals the Studio page's origin, whose source is parent, and whose type is preview-regression-barrier. The script posts the barrier from the Studio page through iframe.contentWindow.postMessage, so all three hold for its own message and nothing else resolves it. The ordering argument from my first review is unchanged.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 22, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 3a68f7b Nov 22, 2026
75 of 77 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-release-seek-race branch November 22, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants